import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../components/Login/Login.vue'
import User from '../components/xitong/User.vue'
import Role from '../components/xitong/Role.vue'
import Modules from '../components/xitong/Modules.vue'
import Welcome from '../components/xitong/Welcome.vue'
import Check from '../components/check/Check.vue'
import Chang from '../components/check/Chang.vue'
import NetStudent from "../components/student/NetStudent.vue"
import MyStudent from '../components/student/MyStudent.vue'
import NetFollow from '../components/student/NetFollow.vue'
Vue.use(VueRouter)

const routes = [{
		path: '/',
		redirect: '/login'
	},
	{
		path: '/home',
		component: Home,
		redirect: '/welcome',
		children:[{
				path: '/welcome',
				component: Welcome
			},
			{
				path: '/user',
				component: User
			},
			{
				path: '/role',
				component: Role
			},
			{
				path: '/modules',
				component: Modules
			},
			{
				path: '/check',
				component: Check
			},
			{
				path: '/chang',
				component: Chang
			},
			{
				path: '/netstudent',
				component: NetStudent
			},
			{
				path: '/mystudent',
				component: MyStudent
			},
			{
				path: '/netfollow',
				component: NetFollow
			}
		]
	},
	{
		path: '/login',
		component: Login
	}
]

const router = new VueRouter({
	routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    next()
    var tokenStr = window.sessionStorage.getItem('token') 
  }
  if (!tokenStr) {
    next()
  } else {
    next('/login')
  }
})
export default router
